home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Just Call Me Internet
/
Just Call Me Internet.iso
/
prog
/
atari
/
m2
/
cat3src
/
cat
/
wildcard.i
< prev
next >
Wrap
Text File
|
1997-10-26
|
4KB
|
126 lines
IMPLEMENTATION MODULE WildCards;
FROM SYSTEM IMPORT ADR;
(*$R-,S-,W-,Z+,J+*)
TYPE chPtr = POINTER TO CHAR;
PROCEDURE WildMat (s, p : chPtr; ignoreCase: BOOLEAN) : BOOLEAN; FORWARD;
PROCEDURE Star (source, pattern : chPtr; ignoreCase: BOOLEAN) : BOOLEAN;
BEGIN
WHILE ~WildMat (source, pattern, ignoreCase) DO
INC (source);
IF source^=0C
THEN
RETURN FALSE
END;
END;
RETURN TRUE;
END Star;
PROCEDURE WildMat (s, p : chPtr; ignoreCase: BOOLEAN) : BOOLEAN;
VAR last : CARDINAL;
match,
reverse : BOOLEAN;
pt : chPtr;
source,
pattern : chPtr;
BEGIN
source := s;
pattern := p;
WHILE (pattern^ # 0C) DO
(* und am Ende source und pattern inkrementieren *)
CASE pattern^ OF
'\' : (* Literal match with following character; fall through *)
(* da schlgt wieder eine 'C'-Besonderheit zu: da in C jeder
* Case durchlaufen wird, bis ein continue oder break kommt,
* wrde in den nchsten Fllen einfach p+1 verglichen. Da
* das in M2 aber nicht geht, mu ich stattdessen source dekrementieren
* anstelle von p zu inkrementieren, damit nach dem nchsten Schleifen-
* durchlauf alles ok ist.
*)
INC (pattern);
IF (pattern^ = 0C) OR (source^ <> pattern^)
THEN
RETURN FALSE;
END; |
(* so, jetzt kommen die interessanten Sachen! *)
'?' : IF source^ = 0C THEN RETURN FALSE END |
'*' : (* Schon etwas komplizierter zu bersetzen *)
INC (pattern);
IF pattern^ = 0C
THEN RETURN TRUE
ELSE RETURN Star (source, pattern, ignoreCase)
END; |
(* So, und jetzt wird's richtig lustig *)
'[' : pt := pattern;
INC (pt);
reverse := (pt^ = '^');
IF reverse THEN INC(pattern) END;
last := 0400;
match := FALSE;
INC(pattern);
WHILE (pattern # NIL) & (pattern^ # ']') DO
IF pattern^='-'
THEN
(* erster Fall: match = true wenn *s<=*++p && *s >=last
*)
INC(pattern);
IF ignoreCase
THEN
match := match OR ((CAP(source^) <= CAP(pattern^)) &
(ORD(source^) >=last));
ELSE
match := match OR ((source^ <= pattern^) &
(ORD(source^) >=last));
END;
ELSE
(* zweiter Fall: match = true wenn *s==*p *)
IF ignoreCase
THEN
match := match OR (CAP(source^)=CAP(pattern^));
ELSE
match := match OR (source^=pattern^);
END;
END;
last := ORD(pattern^);
INC(pattern);
END;
IF match = reverse THEN RETURN FALSE END; |
ELSE
(* Default aus C-Source *)
IF ignoreCase
THEN
IF CAP(source^) # CAP(pattern^) THEN RETURN FALSE END;
ELSE
IF source^ # pattern^ THEN RETURN FALSE END;
END;
END (* CASE *);
INC(pattern);
INC(source);
END; (* WHILE *)
RETURN (source^=0C);
END WildMat;
PROCEDURE NameMatching (REF source, pattern: ARRAY OF CHAR ): BOOLEAN;
BEGIN
RETURN WildMat (ADR(source), ADR(pattern), FALSE);
END NameMatching;
PROCEDURE MatchName (REF source, pattern: ARRAY OF CHAR; ignoreCase: BOOLEAN): BOOLEAN;
BEGIN
RETURN WildMat (ADR(source), ADR(pattern), ignoreCase);
END MatchName;
END WildCards.